package com.zyk.plugin.dns;

import com.zyk.Environment;
import com.zyk.plugin.JaTransformer;
import com.zyk.plugin.PluginConfig;
import com.zyk.plugin.PluginEntry;
import com.zyk.common.ConfigParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;

public class DNSFilterPlugin implements PluginEntry {
    private static final Logger LOGGER = LoggerFactory.getLogger(DNSFilterPlugin.class);
    private static final String PLUGIN_NAME = "DNS";

    Environment environment;
    PluginConfig pluginConfig;

    @Override
    public void init(Environment environment) {
        this.environment = environment;
        try {
            pluginConfig = new PluginConfig(ConfigParser.parseFromYaml(
                    this.getClass().getClassLoader().getResourceAsStream("dns.config.yml")));
        } catch (Exception e){
            LOGGER.error("init plugin failed.", e);
        }
    }

    @Override
    public List<JaTransformer> getJaTransformers() {
        return Arrays.asList(new InetAddressTransformer());
    }

    @Override
    public String getName() {
        return PLUGIN_NAME;
    }

    @Override
    public String getDescription() {
        return "A plugin for the ja, it can block dns resolution.";
    }

}